package com.tc.serial;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.preference.PreferenceManager;

public class WorkingConfig {
	static public boolean simulator = true;
	static public boolean mainController = false;
	static WorkingConfig instance;
	static public WorkingConfig getInstance(){
		return instance;
	}
	
	Context context;
	static public void init(Context ctx){
		instance = new WorkingConfig(ctx);
	}
	public boolean validProxy(){

		return serverIp != null && port != 0;
	}
	public boolean validMainController(){
		
		return port != 0;
	}
	public WorkingConfig(Context ctx) {
		super();
		this.context = ctx;
		SharedPreferences pref = PreferenceManager
		.getDefaultSharedPreferences(ctx);
		serverIp = pref.getString("homeProxyIp", null);
		int p = pref.getInt("homeProxyPort", 0);
	
			port = (short)p;
			
	}
	String serverIp;
	public String getServerIp() {
		return serverIp;
	}
	public void setServerIp(String serverIp) {
		this.serverIp = serverIp;
	}
	public short getPort() {
		return port;
	}
	public void setPort(short port) {
		this.port = port;
	}
	public short port;
	boolean remote = true;
	public boolean isRemote() {
		return remote;
	}
	public void setRemote(boolean remote) {
		this.remote = remote;
	}
	public void save() {
		SharedPreferences pref = PreferenceManager
		.getDefaultSharedPreferences(context);
		Editor e = pref.edit();

		e.putString("homeProxyIp", serverIp);
		e.putInt("homeProxyPort", port);
		e.commit();
		
	}
	
}
